﻿using OCR.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OCR.SystemThread
{
    class CreateFolderThread
    {
        public static bool CreateFolder_Flowrec = false;
        public static Thread CreateFolderFlow_Thread = null;
        public static int iCreateFolder_Step = 0;

        public static bool CreateFolder_Pause = false;

        public static string currSaveImgPath;

        public static readonly object folderLock = new object();
        public static void CreateFolder_Thread()
        {
            CreateFolder_Flowrec = true;
            CreateFolderFlow_Thread = new Thread(CreateFolderFlowThread);
            CreateFolderFlow_Thread.IsBackground = true;
            CreateFolderFlow_Thread.Start();


        }
        private static void CreateFolderFlowThread(object obj)
        {
            while (CreateFolder_Flowrec)
            {

                switch (iCreateFolder_Step)
                {
                    case 10:

                        if (!CreateFolder_Pause)
                        {
                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH-mm"));
                            currSaveImgPath = LocalInfo.outImgPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm") + "\\";
                            try
                            {
                                if (!Directory.Exists(currSaveImgPath))
                                {
                                    Directory.CreateDirectory(currSaveImgPath);
                                    Console.WriteLine($"创建文件夹: {currSaveImgPath}");
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine($"错误: {E.Message}");
                            }
                        }
                        Thread.Sleep(600000);

                        break;
                }


            }
        }
    }
}
